<?php
	
	$firstNameErrorMessage = '';
	$lastNameErrorMessage = '';
	$address1ErrorMessage = '';
	$address2ErrorMessage = '';
	$countryErrorMessage = '';
	$dobErrorMessage = '';
	if(!$currentUser->loggedIn)
	{	
		header("location: login.php");
	}
	else if(isset($_POST['btnSave']))
	{
		$accountMessage = '';
		$firstNameErrorMessage = $accountValidationError->isEmpty(trim($_POST['first_name']),'<label class="required">First name is required.</label>');
		$lastNameErrorMessage = $accountValidationError->isEmpty(trim($_POST['last_name']),'<label class="required"> Last name required.</label>');;
		$address1ErrorMessage = $accountValidationError->isEmpty(trim($_POST['address1']),'<label class="required">Address address is required.</label>');
		$address2ErrorMessage = $accountValidationError->isEmpty(trim($_POST['address2']),'<label class="required">Address address is required.</label>');
		$countryErrorMessage = $accountValidationError->isListItemSelected($_POST['country'],'<label class="required">Select a Counrty.</label>');
		$dobErrorMessage = $accountValidationError->isEmpty(trim($_POST['dob']),'<label class="required">DOB is required.</label>');
	}
?>

<?php
	
	if(isset($_POST['btnSave']))
	{
		$formError = $accountValidationError->status;
		
		if($formError==0)
		{
			try
			{
				$currentUser->firstName = $_POST['first_name'];
				$currentUser->lastName = $_POST['last_name'];
				$currentUser->address1 = $_POST['address1'];
				$currentUser->address2 = $_POST['address2'];
				$currentUser->country = $_POST['country'];
				$currentUser->dob= $_POST['dob'];
				
				if($currentUser->updateUser())
				{
					$accountMessage = '<span class="success_msg_span">Basic account information updated successfully.</span>';
				}
				else
				{
					$accountMessage = '<span class="failed_msg_span">An error occured while updating your basic account information.</span>';
				}
			}
			catch(Exception $ex)
			{
				$accountMessage = '<span class="failed_msg_span">'.$ex->getMessage().'</span>';
			}
		}
	}
?>
